#include "Game.h"
#include "Player.h"
#include "Race.h"
#include "Jet.h"
#include "Track.h"
#include "GameState.h"
#include "App.h"
#include "XML_Loader.h"

extern DebugTracer _DEBUGTRACER;
Game::Game(Ogre::SceneNode* root)
{
    m_root = NULL;
    m_race = NULL;
    m_player = NULL;

    m_root = root;
    m_race = new Race();

    m_state = RACING;
    m_dirty = true;

    m_player = new Player();
    m_player->SetName("frutiemax");

    static Track* track = new Track();
    XML_Loader::LoadFromXmlFile(track,"res/test_track2.xml");

    static Jet* jet = new Jet(m_root, track);
    if(XML_Loader::LoadJetFromXmlFile(jet,"res/jet_list.xml","Debug"))
        m_player->ChooseJet(jet);

    m_race->AddPlayer(m_player);

    m_race->SelectTrack(track);

    m_race->Start();

    XML_Loader::SaveTrack(track,"res/test_track3.xml");
}

Game::~Game()
{
    //dtor
}

void Game::Update(float timedelta)
{
    switch(m_state)
    {
        case RACING:
        m_race->Update(timedelta);
        break;
    }
}
void Game::OnAccelerateKey(float timedelta)
{
   m_player->GetJet()->Accelerate(DEFK_SENSITIVITY, timedelta);
}
void Game::OnTurnRightKey(float timedelta)
{
    m_player->GetJet()->Steer(DEFK_SENSITIVITY);
}
void Game::OnTurnLeftKey(float timedelta)
{
    m_player->GetJet()->Steer(-DEFK_SENSITIVITY);
}
void Game::OnBrakeKey(float timedelta)
{
    m_player->GetJet()->Brake(DEFK_SENSITIVITY, timedelta);
}
void Game::OnTurnRightJoystick(float delta)
{
}
void Game::OnTurnLeftJoystick(float delta)
{
}
